package icu.qx.pbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import icu.qx.pbs.mapper.PbsProcedureMaterialMapper;
import icu.qx.pbs.domain.PbsProcedureMaterial;
import icu.qx.pbs.service.IPbsProcedureMaterialService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * 工序物料清单Service业务层处理
 *
 * @author yong
 * @date 2024-06-26
 */
@Service
public class PbsProcedureMaterialServiceImpl implements IPbsProcedureMaterialService {
    @Autowired
    private PbsProcedureMaterialMapper pbsProcedureMaterialMapper;

    /**
     * 查询工序物料清单列表
     *
     * @param pbsProcedureMaterial 工序物料清单
     * @return 工序物料清单
     */
    @Override
    public List<PbsProcedureMaterial> selectPbsProcedureMaterialList(PbsProcedureMaterial pbsProcedureMaterial) {
        return pbsProcedureMaterialMapper.selectPbsProcedureMaterialList(pbsProcedureMaterial);
    }

    @Override
    public PbsProcedureMaterial selectSelfData(PbsProcedureMaterial pbsProcedureMaterial) {
        return pbsProcedureMaterialMapper.selectSelfData(pbsProcedureMaterial);
    }

    /**
     * 新增工序物料清单
     *
     * @return 结果
     */
    @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
    @Override
    public int insertPbsProcedureMaterials(List<PbsProcedureMaterial> pbsProcedureMaterials) {
        try {
            pbsProcedureMaterials.forEach(e -> {
                pbsProcedureMaterialMapper.insertPbsProcedureMaterial(e);
            });
            return 1;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return -1;
        }
    }

    /**
     * 批量删除工序物料清单
     *
     * @return 结果
     */
    @Override
    public int deletePbsProcedureMaterialByPris(PbsProcedureMaterial pbsProcedureMaterial) {
        return pbsProcedureMaterialMapper.deletePbsProcedureMaterialByPris(pbsProcedureMaterial);
    }
}
